$(function() {
	jQuery.fn.extend({
		reload:function(fn) {
			$(this).load($(this).attr("url"), fn);
		}
	});
	
	jQuery.extend({
		bmodal:function(options) {
			var title = options.title;
			var url = options.url;
			var content = options.content;
			var buttons = options.buttons;
			var afterLoad = options.fn;
			var html = '<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"'+
					   '         aria-hidden="true">'+
					   '    <div class="modal-dialog">'+
					   '       <div class="modal-content" style="width: 1000px;margin: 0 0 0 -150px;">'+
					   '            <div class="modal-header">'+
					   '                <button type="button" class="close" data-dismiss="modal">×</button>'+
					   '                <h3>'+title+'</h3>'+
					   '            </div>'+
					   '            <div class="modal-body">'+
					   '            </div>'+
					   '            <div class="modal-footer">'+
					   '            </div>'+
					   '        </div>'+
					   '    </div>'+
					   '</div>';
			var modal = $(html);
			if(url!=null)
				modal.find(".modal-body").load(url, function() {
					if(afterLoad!=null)
						afterLoad();
				});
			else
				modal.find(".modal-body").html(content);
			$.each(buttons, function(i, n){
				var btn = $('<a href="javascript:;" class="btn btn-primary">'+n.text+'</a>');
				console.info(n);
				btn.bind("click", n.click);
				modal.find(".modal-footer").append(btn);
			})
			var oldModal = $("body").find(".modal");
			if(oldModal!=null)
				oldModal.remove();
			$("body").append(modal);
			modal.modal("show");
			return modal;
		}
	})
})
